<template>
	<view class="flex">
		<u-input v-model="content"  class="mr-10 w-full" type="text" border />
		<u-image :src="captcha.img" @click="get" width="220"></u-image>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//后台接口返回的验证码数据
				captcha: {},
				//用户输入的验证码
				content: ""
			}
		},
		watch: {
			content(n) {
				this.$emit("input", {
					content: this.content,
					key: this.captcha.key
				});
			}
		},
		created() {
			this.get();
		},
		methods: {
			async get() {
				// this.captcha = await this.axios.get(`captcha`);
				this.captcha = await this.api.get(`/captcha?_` + Math.random())
			}
		}
	}
</script>

<style>

</style>
